<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head th:include="common/common::jscss"/>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <table class=" layui-table" id="zmn-table" lay-filter="zmn-table" th:fragment="table"
                   style="text-align: center">
                <thead>
                <tr>
                    <th lay-data="{field:'tariffName', unresize:true}" style="text-align: center">价格表名称</th>
                    <th lay-data="{field:'priceType', unresize:true, align:'center'}" style="text-align: center">定价方式
                    </th>
                    <th lay-data="{field:'tariffType', unresize:true, align:'center'}" style="text-align: center">
                        价格表维度
                    </th>
                    <th lay-data="{field:'操作',width:100, unresize:true, align:'center', fixed:'right'}"
                        style="text-align: center">操作
                    </th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="item:${items}">
                    <td th:text="${item.tariffName}"></td>
                    <td th:text="${item.priceType == 1 ? '系数定价' : '城市定价'}"></td>
                    <!--<td th:text="${item.tariffType == 1 ? '服务价格' :(item.tariffType == 2) ? '计价器价格':'提前付价格'}"></td>-->
                    <td th:switch="${item.tariffType}">
                        <div th:case="1">服务价格</div>
                        <div th:case="2">计价器价格</div>
                        <div th:case="3">提前付价格</div>
                        <div th:case="4">计价器3.0价格</div>
                    </td>
                    <td>
                        <a class="btn-choose" style="color: #00a0e9" lay-event="choose"
                           data-th-data-tariffid="${item.tariffId}"
                           data-th-data-tariffname="${item.tariffName}">选择</a>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
</body>
</html>

<script type="text/javascript" th:inline="javascript">

    let json = {
        channelId: [[${channelId}]],
        bizType: [[${bizType}]],
        tariffType: [[${tariffType}]]
    };
    layui.config({
        base: "/static/lay/",
        version: 201908211550
    }).extend({
        index: "lib/index",
    }).use(['index', 'layer'], function () {
        let $ = layui.$;
        let layer = layui.layer;

        $('#zmn-table').on('click', '.btn-choose', function () {
            let $button = $(this);
            let tariffId = $button.data('tariffid');
            let tariffName = $button.data('tariffname');

            let data = {
                channelId: json.channelId,
                bizType: json.bizType,
                tariffType: json.tariffType,
                tariffId: tariffId,
                tariffName: tariffName,
            };
            zmnLayUtil.ajaxSimpleUE("/channel/price/faultprice/bindingPriceTable.action", data, 0, function (resp) {
                if (resp.status == 200) {
                    parent.layer.msg(resp.message, {"icon": 1});
                    let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index);
                    parent.window.location.reload();
                } else {
                    layer.msg(resp.message, {"icon": 2});
                }
            });
        });

    });

</script>
